﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using MiniFox.Components;
using MiniFox.Infrastructure;
using MiniFox.Utility;
using MiniFox.Web.Infrastructure;
using Sys.Core;
using Sys.Core.Models.Dto;
using TemplateEngine;

namespace Sys.Controllers
{
    [Area(GlobalConstants.AREA_NAME)]
    public class TemplateController : MvcControllerBase
    {
        [AutoWired]
        public ITemplateService Service { get; set; }

        [HttpPost, AllowAnonymous]
        public async Task<Response<string>> TestAsync([FromBody] TemplateTestDto request)
        {
            var model = request.Model;
            var templateContent = request.TemplateContent;
            var result = await Service.ResolveAsync(model, templateContent);
            return result.CreateResponse();
        }
        [HttpPost]
        public async Task<Response<string>> ResolveAsync([FromQuery] string name, [FromBody] object model)
        {
            var result = await Service.ResolveAsync(name, model);
            return result.CreateResponse();
        }
    }
}
